﻿using System;

namespace Furiant.Figment.Agents.Inventory
{
    public class InventoryDefinition : IEquatable<InventoryDefinition>
    {
        private readonly string _identifier;
        private readonly string _name;
        private readonly string _description;

        internal InventoryDefinition(string identifier, string name, string description)
        {
            _identifier = identifier;
            _name = name;
            _description = description;
        }

        public string Identifier { get { return _identifier; } }

        public string Name { get { return _name; } }

        public string Description { get { return _description; } }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(InventoryDefinition)) return false;
            return Equals((InventoryDefinition)obj);
        }

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool Equals(InventoryDefinition other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other._identifier, _identifier);
        }

        /// <summary>
        /// Serves as a hash function for a particular type. 
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode()
        {
            return (_identifier != null ? _identifier.GetHashCode() : 0);
        }

        public static bool operator ==(InventoryDefinition left, InventoryDefinition right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(InventoryDefinition left, InventoryDefinition right)
        {
            return !Equals(left, right);
        }
    }
}
